# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=webkitgtk

pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}2"
pkgver=1.10.2
pkgrel=1
pkgdesc="Library for rendering web content, GTK+ Port (mingw-w64)"
arch=('any')
url="http://webkitgtk.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "bison"
    "flex"
    "gperf"
    "libtool"
    "gtk-doc"
    "${MINGW_PACKAGE_PREFIX}-python2"
    "${MINGW_PACKAGE_PREFIX}-ruby"
    )
depends=(
    "${MINGW_PACKAGE_PREFIX}-cairo"
    "${MINGW_PACKAGE_PREFIX}-enchant"
    "${MINGW_PACKAGE_PREFIX}-fontconfig"
    "${MINGW_PACKAGE_PREFIX}-freetype"
    "${MINGW_PACKAGE_PREFIX}-glib2"
    "${MINGW_PACKAGE_PREFIX}-gst-plugins-base0.10"
    "${MINGW_PACKAGE_PREFIX}-gstreamer0.10"
    "${MINGW_PACKAGE_PREFIX}-gtk2"
    "${MINGW_PACKAGE_PREFIX}-geoclue"
    "${MINGW_PACKAGE_PREFIX}-icu"
    "${MINGW_PACKAGE_PREFIX}-libidn"
    "${MINGW_PACKAGE_PREFIX}-libjpeg"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-libsoup"
    "${MINGW_PACKAGE_PREFIX}-sqlite3"
    "${MINGW_PACKAGE_PREFIX}-libxml2"
    "${MINGW_PACKAGE_PREFIX}-libxslt"
    "${MINGW_PACKAGE_PREFIX}-pango"
    "${MINGW_PACKAGE_PREFIX}-xz"
    )
options=(!libtool strip staticlibs)
source=(http://webkitgtk.org/releases/webkitgtk-${pkgver}.tar.xz
    webkitgtk-1.10.2-windows.patch
    bison3.patch)
sha256sums=('19234f8e4edfaefe91ed06471a2aa8c71d26dd55d33787eede1dcfc9a3a96d9c'
            '0dfbd05feeb97cead2ad21771e5d795f4519726233348fa091a0c9bc28fe7af4'
            '0996b25d17be61470678c18db9bfad1bf807aac410690fb8935370dbc8b3ce34')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/webkitgtk-1.10.2-windows.patch
  patch -p1 -i ${srcdir}/bison3.patch
  sed -e "s|-licui18n|-licuin|g" -i configure.ac

  rm -rf autom4te.cache
  touch README INSTALL
  gtkdocize --copy > /dev/null 2>&1
  autoreconf --verbose --install -I Source/autotools
}

build() {
  # Suppress a *lot* of gcc 4.8 warnings
  CPPFLAGS+=" -Wno-unused-local-typedefs"
  export lt_cv_deplibs_check_method='pass_all'

  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  #cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-debug --enable-debug-symbols --disable-debug-features \
    --with-gtk=2.0 --disable-webkit2 --disable-glibtest \
    --enable-shared --disable-static --with-target=win32 \
    --with-unicode-backend=icu --disable-jit \
    --enable-filters --enable-video \
    --with-font-backend=freetype --enable-3D-transforms \
    --enable-geolocation --enable-web-sockets --enable-mathml

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gstreamer*/*.a
}
